package cn.jichangxiu.common.web.model.response;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.ArrayList;
import java.util.List;

@Data
@ToString
@ApiModel("返回对象内容实体")
@NoArgsConstructor
public class QueryResult<T> {
    @ApiModelProperty("数据列表")
    private List<T> data;
    @ApiModelProperty("数据总数")
    private long total;

    public QueryResult(List<T> data) {
        this.data = data;
        this.total = data.size();
    }

    public QueryResult(List<T> data, long total) {
        this.data = data;
        this.total = total;
    }

    public QueryResult(T t) {
        this.data = new ArrayList<>();
        data.add(t);
        this.total = data.size();
    }
}
